<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>运营端首页 - 售后管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f5f5f5;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .header h1 {
            font-size: 24px;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .logout-btn {
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 8px 16px;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .nav-menu {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .nav-menu h2 {
            margin-bottom: 20px;
            color: #333;
        }

        .nav-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
        }

        .nav-item {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px 20px;
            border-radius: 10px;
            text-align: center;
            cursor: pointer;
            transition: transform 0.2s ease;
            text-decoration: none;
        }

        .nav-item:hover {
            transform: translateY(-5px);
        }

        .nav-item h3 {
            font-size: 18px;
            margin-bottom: 10px;
        }

        .nav-item p {
            font-size: 14px;
            opacity: 0.9;
        }

        .stats-section {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
        }

        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
        }

        .stat-number {
            font-size: 32px;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .stat-label {
            font-size: 14px;
            opacity: 0.9;
        }

        .chart-section {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .chart-section h2 {
            margin-bottom: 20px;
            color: #333;
        }

        .chart-container {
            height: 300px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #f8f9fa;
            border-radius: 8px;
            color: #666;
        }

        .loading {
            text-align: center;
            padding: 40px;
        }

        .spinner {
            border: 2px solid #f3f3f3;
            border-top: 2px solid #667eea;
            border-radius: 50%;
            width: 30px;
            height: 30px;
            animation: spin 1s linear infinite;
            display: inline-block;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>售后管理系统 - 运营端</h1>
        <div class="user-info">
            <span>欢迎，<span id="username">运营</span></span>
            <a href="/login" class="logout-btn">退出登录</a>
        </div>
    </div>

    <div class="container">
        <div class="nav-menu">
            <h2>功能菜单</h2>
            <div class="nav-grid">
                <a href="/after_sale_system/page/operator/ruleManagement" class="nav-item">
                    <h3>规则管理</h3>
                    <p>管理售后规则</p>
                </a>
                <a href="/after_sale_system/page/operator/statistics" class="nav-item">
                    <h3>数据统计</h3>
                    <p>查看详细统计</p>
                </a>
                <a href="/after_sale_system/page/operator/systemConfig" class="nav-item">
                    <h3>系统配置</h3>
                    <p>系统参数配置</p>
                </a>
                <a href="/after_sale_system/page/operator/userManagement" class="nav-item">
                    <h3>用户管理</h3>
                    <p>管理用户账户</p>
                </a>
            </div>
        </div>

        <div class="stats-section">
            <h2>统计概览</h2>
            <div class="stats-grid">
                <div class="stat-card">
                    <div class="stat-number" id="totalApplications">0</div>
                    <div class="stat-label">总申请数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" id="totalUsers">0</div>
                    <div class="stat-label">注册用户数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" id="avgSatisfaction">0</div>
                    <div class="stat-label">平均满意度</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" id="activeRules">0</div>
                    <div class="stat-label">活跃规则数</div>
                </div>
            </div>
        </div>

        <div class="chart-section">
            <h2>趋势分析</h2>
            <div class="chart-container" id="trendChart">
                <div class="loading">
                    <div class="spinner"></div>
                    <p>加载图表中...</p>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 页面加载时获取数据
        window.addEventListener('load', function() {
            loadUserInfo();
            loadStatistics();
            loadTrendData();
        });

        // 获取用户信息
        function loadUserInfo() {
            fetch('/after_sale_system/api/user/info')
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        document.getElementById('username').textContent = data.data.username;
                    }
                })
                .catch(error => {
                    console.error('获取用户信息失败:', error);
                });
        }

        // 获取统计数据
        function loadStatistics() {
            fetch('/after_sale_system/api/statistics/')
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        const stats = data.data;
                        document.getElementById('totalApplications').textContent = stats.totalApplications || 0;
                        document.getElementById('totalUsers').textContent = stats.totalUsers || 0;
                        document.getElementById('avgSatisfaction').textContent = (stats.avgSatisfaction || 0).toFixed(1);
                        document.getElementById('activeRules').textContent = stats.activeRules || 0;
                    }
                })
                .catch(error => {
                    console.error('获取统计数据失败:', error);
                });
        }

        // 获取趋势数据
        function loadTrendData() {
            fetch('/after_sale_system/api/statistics/trend?metric=applications&timeRange=week')
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        displayTrendChart(data.data);
                    } else {
                        console.error('获取趋势数据失败:', data.message);
                    }
                })
                .catch(error => {
                    console.error('获取趋势数据失败:', error);
                });
        }

        // 显示趋势图表
        function displayTrendChart(trendData) {
            const container = document.getElementById('trendChart');
            
            if (!trendData || trendData.length === 0) {
                container.innerHTML = '<p>暂无趋势数据</p>';
                return;
            }

            // 这里可以集成图表库如Chart.js来显示图表
            // 目前使用简单的文本显示
            container.innerHTML = `
                <div style="text-align: center; padding: 20px;">
                    <h3>申请趋势</h3>
                    <p>最近7天申请数量变化</p>
                    <div style="margin-top: 20px;">
                        ${trendData.map(item => `
                            <div style="display: inline-block; margin: 0 10px; text-align: center;">
                                <div style="font-size: 24px; font-weight: bold; color: #667eea;">${item.value}</div>
                                <div style="font-size: 12px; color: #666;">${item.date}</div>
                            </div>
                        `).join('')}
                    </div>
                </div>
            `;
        }
    </script>
</body>
</html> 